package cn.ronghuanet.listener;

import cn.ronghuanet.permission.service.IPermissionScanService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * 定义监听器
 * 1 写一个普通类,实现ServletContextListener
 * 2 类上加@WebListener
 * 3 在启动类上面添加@ServletComponentScan("cn.ronghuanet.listener"),来扫描这个包下面的Servlet组件,包括监听器 过滤器等等
 */
@WebListener
public class PermissionScanListener implements ServletContextListener {

    @Autowired
    private IPermissionScanService permissionScanService;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("容器初始化开始......................................");
        // 容器初始化之后,做权限扫描
        permissionScanService.scan();
        System.out.println("容器初始化结束......................................");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("容器销毁.......................................");
    }
}
